<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" th:inline="javascript">
        /*<![CDATA[*/
        var basePath =/*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;
        function getBaseUrl() {
            $("#basePathUrl").val(basePath);
            var a = $("#basePathUrl").val();
            return a;
        }
        var sessionuser=/*[[${session.sessionUsers.id}]]*/;

        function getuser(){
            $("#sessionuser").val(sessionuser);
            var a = $("#sessionuser").val();
            return a;
        }
        /*]]>*/
    </script>
</head>
<body>
<!-- 引入url -->
<input type="hidden" id="basePathUrl"/>
<input type="hidden" id="sessionuser"/>

<!--
例子：
引入在body中：<span th:include="fragments/basepath::html"></span>
script中
    var baseUrl = getBaseUrl();
    var sessionuser=getuser();
    可取值
-->
</body>
</html>